<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>
            <el-button
              v-if="isAuth('module:business:quote:container:form')"
              type="success"
              icon="Plus"
              @click="router.push({ name: 'module_business_quote_container_form' })">
              {{ i18n('common.create') }}
            </el-button>

            <el-button
              v-if="isAuth('module:business:quote:container:import:list')"
              class="el-button--cyan"
              icon="FirstAidKit"
              @click="router.push({ name: 'module_business_quote_container_import_list' })">
              {{ i18n('common.import') }}
            </el-button>
          </div>
        </div>

        <div class="admin_main_block_right">
          <div>
            <el-button
              v-if="isAuth('module:business:quote:container:delete')"
              type="danger"
              icon="Delete"
              @click="deleteHandle()">
              {{ i18n('common.batch_delete') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_main_block_select">
        <div class="input">
          <el-select
            v-model="dataForm.shipowner_id"
            :placeholder="i18n('common.please_select') + i18n('business.quote.container.shipowner_id')"
            clearable>
            <el-option :label="i18n('common.all')" value=""></el-option>
            <el-option v-for="(v, k) in shipownerList" :label="v.chinese_name" :key="k" :value="v.scac">
            </el-option>
          </el-select>
        </div>
        <div class="input">
          <el-input v-model="dataForm.start_harbor_code" :placeholder="$t('common.please_input') + $t('business.quote.container.start_harbor_code')" clearable>
          </el-input>
        </div>
        <div class="input">
          <el-input v-model="dataForm.end_harbor_code" :placeholder="$t('common.please_input') + $t('business.quote.container.end_harbor_code')" clearable>
          </el-input>
        </div>
        <div class="input">
          <el-select v-model="dataForm.status" :placeholder="$t('common.please_select') + $t('common.status')" clearable>
            <el-option :label="$t('common.all')" value=""></el-option>
            <el-option :label="$t('common.enable')" value="1"></el-option>
            <el-option :label="$t('common.disable')" value="2"></el-option>
          </el-select>
        </div>
        <div class="date">
          <el-date-picker v-model="dataForm.publish_time" type="daterange" :range-separator="$t('common.to')" :start-placeholder="$t('common.start_time')" :end-placeholder="$t('common.end_time')" clearable>
          </el-date-picker>
        </div>
        <div class="input">
          <el-button icon="Search" @click="getDataList(true)">
            {{ i18n('common.search') }}
          </el-button>
        </div>
      </div>
      <div class="admin_table_main">
        <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" stripe>
          <el-table-column type="selection" header-align="center" align="center">
          </el-table-column>

          <el-table-column prop="id" :label="i18n('common.id')" width="70">
          </el-table-column>

          <el-table-column :label="i18n('business.quote.container.shipowner_id')" width="180">
            <template v-slot="scope">
              <el-text v-if="scope.row.shipowner">
                {{ scope.row.shipowner.chinese_name }}
              </el-text>
            </template>
          </el-table-column>

          <el-table-column prop="start_harbor_code" :label="i18n('business.quote.container.start_harbor_code')" width="110">
          </el-table-column>

          <el-table-column :label="i18n('business.quote.container.start_harbor_name')" min-width="150">
            <template v-slot="scope">
              <dl class="table_dl" v-if="scope.row.start">
                <dd class="table_dl_dd_all_30">
                  <el-text>{{ scope.row.start.chinese_name }}</el-text>
                </dd>
                <dd class="table_dl_dd_all_16_gray">
                  <el-text>{{ scope.row.start.english_name }}</el-text>
                </dd>
              </dl>
            </template>
          </el-table-column>

          <el-table-column prop="end_harbor_code" :label="i18n('business.quote.container.end_harbor_code')" width="110">
          </el-table-column>

          <el-table-column :label="i18n('business.quote.container.end_harbor_name')" min-width="150">
            <template v-slot="scope">
              <dl class="table_dl" v-if="scope.row.end">
                <dd class="table_dl_dd_all_30">
                  <el-text>{{ scope.row.end.chinese_name }}</el-text>
                </dd>
                <dd class="table_dl_dd_all_16_gray">
                  <el-text>{{ scope.row.end.english_name }}</el-text>
                </dd>
              </dl>
            </template>
          </el-table-column>

          <el-table-column :label="$t('common.status')" width="80">
            <template v-slot="scope">
              <el-switch
                v-model="scope.row.status.value"
                active-value="1"
                inactive-value="2"
                size="large"
                inline-prompt
                :active-text="$t('common.enable')"
                :inactive-text="$t('common.disable')"
                style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
                @change="handleStatus($event, scope.row.id, 'status')">
              </el-switch>
            </template>
          </el-table-column>

          <el-table-column prop="publish_time" :label="i18n('business.quote.container.publish_time')" width="100">
          </el-table-column>

          <el-table-column :label="i18n('common.handle')" fixed="right" width="200">
            <template v-slot="scope">
              <el-button
                v-if="isAuth('module:business:quote:container:form')"
                type="primary"
                icon="Edit"
                @click="router.push({ name: 'module_business_quote_container_form', query: { id: scope.row.id } })">
                {{ i18n('common.update') }}
              </el-button>

              <el-button
                v-if="isAuth('module:business:quote:container:delete')"
                type="danger"
                icon="Delete"
                @click="deleteHandle(scope.row.id)">
                {{ i18n('common.delete') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next,jumper,total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="business-quote-container-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('business/quote/container')

  const shipownerList = ref([])

  const dataForm = reactive([
    'shipowner_id',
    'start_harbor_code',
    'end_harbor_code',
    'publish_time',
    'status',
  ])

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    selectionChangeHandle,
    getDataList,
    handleStatus,
    deleteHandle,
  } = useTable(model.value, dataForm)

  const loadShipownerList = () => {
    $http({
      url: $http.adornUrl('/business/shipowner/select'),
      method: 'get',
      params: $http.adornParams({}),
    }).then(({data}) => {
      if (data && data.status === 200) {
        shipownerList.value = data.data
      } else {
        $message.error(data.message)
      }
    })
  }

  onMounted(() => {
    getDataList(model)

    loadShipownerList()
  })
</script>
